/*
{
"状态":1,
"名称":"修改-cmd权限资料",
"作者":"陈泽椿",
"创建时间":"2018-10-29",
"功能":"修改-cmd权限资料",
"log": [
	{"date":"06-01" , "dev" :"hzhh" , "content" : ""}
]
}
*/
declare @cmd_key int,@cmd_id varchar(100) ,@cmd_name varchar(100) , @classify varchar(100) , @remarks varchar(100)
declare @cmd_id_old varchar(100)
DECLARE @cmd_power_id varchar(100)
set @cmd_key = '{cmd_key}'
set @cmd_id = '{cmd_id}'
set @cmd_name = '{cmd_name}'
set @classify ='{classify}' 
set @remarks = '{remarks}'
SET @cmd_power_id='{cmd_power_id}'
--校验信息
if isnull(@cmd_id,'')=''
begin 
	RAISERROR ('SQL:cmd_id不允许为空', 16 ,1 ) ; 
	return 
end 

if isnull(@cmd_name,'')=''
begin 
	RAISERROR ('SQL:cmd名称不允许为空', 16 ,1 ) ; 
	return 
end 

if isnull(@classify,'')=''
begin 
	RAISERROR ('SQL:cmd分类不允许为空', 16 ,1 ) ; 
	return 
end 

IF EXISTS(SELECT * FROM y_cmd WHERE [cmd_key] <> @cmd_key and cmd_id=@cmd_id)
begin
	RAISERROR ('SQL:cmd_id已经存在', 16 ,1 ) ; 
	return 
end  


IF ISNULL(@cmd_power_id,'')<>'' AND NOT EXISTS(SELECT 1 FROM dbo.y_power WHERE power_id=@cmd_power_id AND classify='10001')
BEGIN
	RAISERROR ('SQL:权限不存在', 16 ,1 ) ; 
	return 
END 

select @cmd_id_old=cmd_id from y_cmd where [cmd_key] = @cmd_key
 
update [dbo].[y_cmd] set
[cmd_id] = @cmd_id ,
[cmd_name] = @cmd_name ,
[classify] = @classify ,
[remarks] = @remarks , 
[cmd_power_id]=@cmd_power_id,
[update_time] = getdate()
where [cmd_key] = @cmd_key
